import Const from '../utils/const'
export default {
  namespaced: true,
  state: {
    currentUserId: '',
    userInfo: {
      id: '1',
      phone: '',
      nickname: '',
      gender: '男'
    },
    appConst: {}
  },

  getters: {
    userGender: state => {
      return state.userInfo.gender
    }
  },

  mutations: {
    SET_USER_INFO: (state, payload) => {
      state.userInfo = {
        ...state.userInfo,
        ...payload.user
      }
    },
    SET_APP_CONST: (state, payload) => {
      state.appConst = { ...state.appConst, ...payload }
    }
  },

  actions: {
    /** 同步方式 */
    updateUserInfo: ({ commit }, payload) => {
      commit('SET_USER_INFO', payload)
    },
    /** 异步处理 */
    updateAppConstPro: ({ commit }, payload) => {
      return axios
        .get(Const.API.GET_APP_CONST)
        .then(res => {
          commit('SET_APP_CONST', res.data)
          return Promise.resolve(res.data)
        }).catch(err => {
          console.log('updateAppConstPro err:', err)
        })
    }
  }
}
